package com.guilang.localmusic.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.guilang.localmusic.R;
import com.guilang.localmusic.SongItem;

import java.util.List;

public class SongsAdapter extends ArrayAdapter {

    private final int imageResource;


    public SongsAdapter(Context context, int resourceId, List<SongItem> objects) {
        super(context, resourceId, objects);
        imageResource = resourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        SongItem songItem = (SongItem) getItem(position);
        //获取布局文件方便寻找ID
        View view = LayoutInflater.from(getContext()).inflate(imageResource, parent, false);
        ImageView songImage = view.findViewById(R.id.song_image);
        TextView songName = view.findViewById(R.id.song_name);
        TextView singer = view.findViewById(R.id.singer);
        songImage.setImageResource(R.mipmap.avater);
        songName.setText(songItem.getSongName());
        singer.setText(songItem.getSinger());
        return view;
    }
}
